/**
 * 入库验收
 * Created by Wayne on 2015/7/16.
 */

define(function(require, exports, module) {
	'use strict';
	module.exports = function(app) {
		app.register.controller('warehouseCtrl', ['$scope', '$location', 'tempData', 'MHService', 'Upload',
			function($scope, $location, tempData, MHService, Upload) {
				var toast = require('../services/mh-toast');
				$scope.feed = tempData.data;
				// console.log(tempData.data);
				if($scope.feed==undefined) {
					$location.path('/feedManage');
				}
				$scope.onFileSelect = function($files) {
					if($files.length==0) {
			          	return;
			        }
			        var file = $files[0];
		          	Upload.upload({url: MHService.URL.img_upload, method: 'POST', file: file}).success(function(res) {
			            console.log(res.data);
			            $scope.attach = res.data;
		          	});
				}

				$scope.postWarehouse = function() {
					if($scope.attach==undefined) {
						$scope.attach = '';
					}
					var config = {
						url: MHService.URL.storage_add,
						_req: {
							id: $scope.feed.id,
							des: $scope.des,
							account: $scope.account,
							attach: $scope.attach,
							code: $scope.code
						}
					};
					MHService.postReq(config, function(data) {
						console.log(data);
						toast.show('成功，返回提料管理。');
						$location.path('/feedManage');
					})
				}
			}
		])
	}
})